package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.customer_service.dto.NoticeQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.SendNoticeViewDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.NoticeAddDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.SendNoticeSmsDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.ChatRecordQueryDTO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.service.NoticeService;
import com.yxw.yxnet_cd_center.customer_service.vo.ChatRecordVo;
import com.yxw.yxnet_cd_center.customer_service.vo.YxCsNoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 消息设置
 * @author liuxin
 * @date 2023.09.15
 */
@RestController
@Api(value = "消息设置管理", tags = "消息设置管理")
@Slf4j
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation(value = "消息设置-消息通知列表查询")
    @PostMapping(value = "/getNoticeList")
    public BaseResult<PageVO<YxCsNoticeVo>> getWorkflowList(@RequestBody NoticeQueryDTO dto) {
        PageVO<YxCsNoticeVo> pageVo=noticeService.pageNoticeList(dto);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    @ApiOperation(value = "消息设置-新增消息通知")
    @PostMapping(value = "/addNotice")
    public BaseResult addNotice(@RequestBody @Validated NoticeAddDTO dto) {
        YxCsNoticeVo vo=noticeService.addNotice(dto);
        return BaseResult.doSuccess(vo,"新增成功");
    }

    @ApiOperation(value = "消息设置-修改消息通知")
    @PostMapping(value = "/updateNotice")
    public BaseResult updateNotice(@RequestBody @Validated NoticeAddDTO dto) {
        noticeService.updateNotice(dto);
        return BaseResult.doSuccess(null,"修改成功");
    }

    @ApiOperation(value = "消息设置-消息通知详情")
    @GetMapping(value = "/getNoticeInfoById")
    public BaseResult getNoticeInfoById(@RequestParam Long id) {
        YxCsNoticeVo vo=noticeService.getNoticeInfoById(id);
        return BaseResult.doSuccess(vo,"查询成功");
    }
    @ApiOperation(value = "消息设置-删除消息通知")
    @DeleteMapping(value = "/deleteNoticeById")
    public BaseResult deleteNoticeById(Long id) {
        noticeService.deleteNoticeById(id);
        return BaseResult.doSuccess(null,"删除成功");
    }

    @ApiOperation(value = "消息设置-消息通知状态修改")
    @PostMapping(value = "/updateStatusById")
    public BaseResult updateStatusById(Long id) {
        noticeService.updateStatusById(id);
        return BaseResult.doSuccess(null,"设置成功");
    }


    @ApiOperation(value = "消息设置-聊天记录列表统计")
    @PostMapping(value = "/pageChatRecord")
    public BaseResult<PageVO<ChatRecordVo>> pageChatRecord(@RequestBody ChatRecordQueryDTO dto){
        PageVO<ChatRecordVo> pageVo=noticeService.pageChatRecord(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @ApiOperation(value = "消息提醒-页面提醒发送")
    @PostMapping(value = "/sendNoticeToView")
    public BaseResult sendNoticeToView(@RequestBody SendNoticeViewDTO dto) {
        noticeService.sendNoticeToView(dto);
        return BaseResult.doSuccess(null, "发送成功");
    }

    @ApiOperation(value = "消息提醒-短信推送")
    @PostMapping(value = "/sendNoticeToSms")
    public BaseResult sendNoticeToSms(@RequestBody SendNoticeSmsDTO dto) {
        noticeService.sendNoticeToSms(dto);
        return BaseResult.doSuccess(null, "发送成功");
    }

    @ApiOperation(value = "轮询消息提醒-页面消息推送")
    @PostMapping(value = "/pushCircleNoticeToView")
    public BaseResult pushCircleNoticeToView(@RequestBody SendNoticeViewDTO dto) {
        noticeService.pushCircleNoticeToView(dto);
        return BaseResult.doSuccess(null, "发送成功");
    }

    @ApiOperation(value = "轮询消息提醒取消")
    @PostMapping(value = "/cancelNoticeToView")
    public BaseResult cancelNoticeToView(@RequestBody SendNoticeViewDTO dto) {
        noticeService.cancelNoticeToView(dto);
        return BaseResult.doSuccess(null, "取消成功");
    }

    @ApiOperation(value = "抽取客服接待客户数统计（群维度）")
    @PostMapping(value = "/execChatStatistics")
    public BaseResult execChatStatistics() {
        noticeService.execChatStatistics();
        return BaseResult.doSuccess(null, "执行成功");
    }
}
